package com.aduerr.v1shouyin.mvp.activity;

import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.aduerr.v1shouyin.App;
import com.aduerr.v1shouyin.R;
import com.aduerr.v1shouyin.util.ToastUtils;
import com.orhanobut.hawk.Hawk;
import com.yeahka.shouyintong.sdk.action.LockPos;
import com.yeahka.shouyintong.sdk.api.SytApi;
import com.yeahka.shouyintong.sdk.api.SytFactory;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * @author HI
 * @email dev1024@foxmail.com
 * @time 2021/1/18 9:36
 * @change
 * @chang time
 * @class describe
 */

public class UnionSettingActivity extends AppCompatActivity {
    @BindView(R.id.cb_union_switch)
    CheckBox mCbSwitch;
    @BindView(R.id.tv_title)
    TextView mTvTitle;

    Unbinder unbinder;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_union_setting);
        unbinder=ButterKnife.bind(this);
        mTvTitle.setText("收银通设置");
        boolean isLsLocked = Hawk.get("isLsLocked", false);
        mCbSwitch.setChecked(isLsLocked);
        final SytApi sytApi = SytFactory.createSytIml(this);
        LockPos.Req req = new LockPos.Req();
        mCbSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                req.isLock = isChecked;
                sytApi.sendReq(req);
                Hawk.put("isLsLocked", isChecked);
                ToastUtils.showToast(App.getApp(),isChecked?"收银通锁定功能已开启":"收银通锁定功能已关闭");
            }
        });
    }

    @Override
    protected void onDestroy() {
        if(unbinder !=null){
            unbinder.unbind();
        }
        super.onDestroy();
    }

    @OnClick({R.id.img_back})
    public void onClick(View view) {
        finish();
    }
}
